// Copyright 2019, Chen Shuaihao.
//
//Author: Chen Shuaihao
//
//Poller类，对epoll的封装

#ifndef _POLLER_H_
#define _POLLER_H_

#include <vector>
#include <mutex>
#include <map>
#include <sys/epoll.h>
#include "Net.h"

class Poller
{
public:
    //事件指针数组类型
    typedef std::vector<struct epoll_event> EventList;

    
    //epoll实例
    int pollfd_;

    //events数组，用于传递给epollwait
    std::vector<struct epoll_event> eventlist_;

    //事件表
    //std::map<int, void*> channelmap_;
    
    //保护事件map的互斥量
    std::mutex mutex_;

    Poller();
    ~Poller();

    //等待事件，epoll_wait封装
    void poll(EventList& eList);

    //添加事件，EPOLL_CTL_ADD
    void AddEvent(sClient * p_Conn ,int  nFd, uint32_t  eventType);

    //移除事件，EPOLL_CTL_DEL
    void RemoveEvent(sClient* p_Conn, int  nFd, uint32_t  eventType);

    //修改事件，EPOLL_CTL_MOD
    void UpdateEvent(sClient* p_Conn, int  nFd, uint32_t  eventType, int  nAdd);
private:

};


#endif